<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/h-ui/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/h-ui/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/h-ui/h-ui.admin/skin/default/skin.css"/>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/h-ui/h-ui.admin/css/style.css" />

</head>
<body style="overflow: hidden; width: 98%; height: 100%;" >
		<!-- 工具按钮区 -->
		
 		<div class="panel panel-primary" style="padding-left: 5px;">
 			<div style="padding-top: 4px;padding-bottom: 4px;">
				<a id="bindUser" class="btn btn-primary radius"><span class="glyphicon glyphicon-copy"></span>&nbsp;绑定</a>
			</div>
			<div >
				<table class="table table-border table-bordered table-bg">
					<thead>
						<tr>
							<th scope="col" colspan="9">用户列表</th>
						</tr>
						<tr class="text-c">
							<th width="25"><input type="checkbox" name="" value=""></th>
							<th width="40">ID</th>
							<th width="150">用户账号</th>
						</tr>
					</thead>
 					<c:forEach items="${userList}" var="user" varStatus="stat">
						<tr class="text-c">
						<td><input type="checkbox" name="checkUser" id="box_${stat.index}" value="${user.id}"></td>
						<td>${stat.index+1}</td>
						<td>${user.username}</td>
					</tr>
					</c:forEach>
				</table>
				
			</div>
               
		</div>
<!--_footer 作为公共模版分离出去-->
<script src="${pageContext.request.contextPath}/static/js/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/h-ui/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/h-ui/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath}/static/h-ui/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer /作为公共模版分离出去-->
<script type="text/javascript" src="${pageContext.request.contextPath}/static/lib/laypage/1.2/laypage.js"></script>
	<script type="text/javascript">

     $(function(){    	 
    	 $("#bindUser").click(function(){
    		 
    	    //获取选中的checkbox
     		var boxes = $("input[id^='box_']:checked");
     		if(boxes.length==0){
     			layer.msg('请选择一条数据!',{icon:5,time:1000});	
     			return;
     		}else{
     			var array = new Array(); 	    	
 					$.each(boxes,function(){
 		    			array.push(this.value);
 		    		})
 		    		//发送绑定请求
 		    		$.post("${pageContext.request.contextPath}/back/userPKRole/bindUser.htm",{"userIds":array.join(","),"roleId":${roleId}},function(data){
						if(data.code==0){
							layer.msg('绑定用户成功!',{icon:1,time:1000});
							setTimeout(function () {
								window.parent.location.href = "${pageContext.request.contextPath}/back/role/role-add-user.htm?roleId="+${roleId};
			                }, 1500);
							
						}else{
							layer.msg('绑定用户失败!',{icon:1,time:1000});
						}
					},"json");
				}
 		    		/* //window.location = "${pageContext.request.contextPath}/back/userPKRole/bindUser.htm?userIds="+array.join(",")+"&roleId="+${roleId}; */   		 
    	 })
     })
    
</script>
</body>
</html>